1. Field of the Invention
This invention relates generally to the field of 3-D graphics and, more particularly, to a system and method for determining the orientation of triangles which represent a graphical object.
2. Description of the Related Art
Prior art graphics systems have typically represented objects as a collection of triangles. Each triangle may comprise three vertices with assigned color values and represents a localized portion of some object. In certain situations, the two sides of a triangle may be treated differently by a rendering algorithm. For example, a triangle on the surface of an opaque sphere has a side interior to the sphere and a side exterior to the sphere. The interior side of the triangle may be invisible with respect to viewpoints outside the sphere. Thus, before transmitting the triangle to a rendering agent (which implements the rendering algorithm), some indication of the exterior side may be associated with the triangle vertex data. The rendering algorithm may detect the indication and selectively perform rendering computations only for the exterior side of the triangle.
More generally, triangles are assigned an orientation which selects one of the sides of the triangle prior to transmission to a rendering agent. The rendering agent may receive a stream of triangles (e.g. as a stream of vertices), and may determine the orientation of each triangle. Furthermore, the rendering agent may determine if the selected side of each triangle is front-facing or back-facing with respect to a current viewpoint. If the selected side of a triangle is back-facing, triangle rendering computations may be skipped. In prior art systems, determination of the triangle orientation has involved calculating at least a partial cross-product. Because the partial cross-product is a relatively slow computation, there exists a need for a system and method which could determine triangle orientation without performing a time-consuming cross product computation. Such a system and method may improve the performance of rendering agents (e.g. graphics rendering boards, software rendering applications, etc.) per unit cost.
A graphics system may, in one embodiment, comprise a rendering unit and a filtering unit (e.g. a convolve unit). The rendering unit may comprise one or more processors (e.g. DSP chips), dedicated hardware, or any combination thereof. The rendering unit may be configured to receive graphics data including three vertices defining a triangle. The vertices may be presented as coordinate pairs with respect to the coordinate axes of a virtual screen space. The rendering unit is further configured to generate a first octant identifier word for a first edge of the triangle and a second octant identifier word for a second edge of the first triangle. In most cases, the two octant identifier words determine the triangle orientation. In a few cases (i.e. in those cases where the two octant identifier words correspond to the same octant or opposite octants), the triangle orientation may be resolved by a comparison of the slopes of the first edge and the second edge.
In one embodiment, the rendering unit may perform further rendering operations on a triangle only if the triangle is front-facing, i.e. if the triangle orientation takes a first value which indicates that the triangle is facing towards the virtual viewer in a 3D coordinate space. Back-facing triangles (i.e. triangles with orientation different from the first value) may be rejected. In another embodiment, the rendering unit may be configured to appropriately handle some or all back-facing triangles (e.g. back-facing triangles that have a back-face render bit equal to one). For example, the rendering unit may negate a normal vector associated with the back-facing triangle (effectively redefining the back face as the front face), access property data associated with the back-face, invoke a light computation for the back face, etc.
It is noted that the triangle orientation may be used to determine which side of a triangle edge is interior to the triangle. The rendering unit may then test samples with respect to the triangle edge to determine if they fall on the interior side. Samples which fall on the interior side of all three triangle edges are interior to the triangle.
Rendering computations include computations such as the interpolation of ordinate values (e.g. color values) at locations interior to the triangle. Rendering units may store ordinate values in the sample buffer. A sample-to-pixel calculation unit may read the sample buffer and filter one or more of the ordinate values to generate pixel values which may be transmitted to a display device.